<?php
/* @var $this PostsController */
/* @var $model Posts */
/* @var $form CActiveForm */
?>

<div class="content">
    <div class="grid">
        <div class="grid-title">
            <div class="pull-left">Nội dung bài viết mới</div>
            <div class="pull-right"></div>
            <div class="clear"></div>
        </div>

        <div class="grid-content">
            <?php
            $form = $this->beginWidget('CActiveForm', array(
                'id' => 'posts-form',
                'enableAjaxValidation' => false,
                'htmlOptions' => array('enctype' => 'multipart/form-data'),
            ));
            ?>
            <div class="formRow">
                <?php echo $form->labelEx($model, 'title'); ?>
                <div class="formRight">
                    <?php echo $form->textField($model, 'title', array('size' => 60, 'maxlength' => 500)); ?>
                </div>
            </div>
            <div class="formRow">
                <?php echo $form->labelEx($model, 'slug'); ?>
                <div class="formRight">
                    <?php echo $form->textField($model, 'slug', array('size' => 60, 'maxlength' => 500)); ?>
                </div>
            </div>
            <div class="formRow">
                <?php echo $form->labelEx($model, 'keywords'); ?>
                <div class="formRight">
                    <?php echo $form->textField($model, 'keywords'); ?>
                </div>
            </div>
            <div class="formRow">
                <?php echo $form->labelEx($model, 'description'); ?>
                <div class="formRight">
                    <?php echo $form->textField($model, 'description'); ?>
                </div>
            </div>

            <div class="formRow">
                <?php echo $form->labelEx($model, 'desc'); ?>
                <div class="formRight">
                    <?php echo $form->textArea($model, 'desc', array('rows' => 6, 'cols' => 50)); ?>
                </div>
            </div>



            <div class="formRow">
                <?php echo $form->labelEx($model, 'content'); ?>
                <div class="formRight">
                    <?php
                    echo $form->textArea($model, 'content', array(
                        'rows' => 6,
                        'cols' => 50,
                        'id' => 'i1',
                    ));
                    ?>
                </div>
            </div>


            <div class="formRow">
                <?php echo $form->labelEx($model, 'picture'); ?>
                <div class="formRight">
                    <?php echo $form->fileField($model, 'image'); ?>
                    <?php if (!empty($model->picture)): ?>
                        <?php echo $form->hiddenField($model, 'picture_hidden', array('value' => $model->picture)); ?>
                        <div><?php echo CHtml::image($model->urlPhoto); ?></div>
                    <?php endif; ?>
                </div>
            </div>

            <div class="formRow">
                <?php echo $form->labelEx($model, 'cat_id'); ?>
                <div class="formRight">
                    <?php echo $form->dropDownList($model, 'cat_id', Categrory::getCatlist()); ?>
                </div>
            </div>

            <div class="formRow">
                <?php echo $form->labelEx($model, 'status'); ?>
                <div class="formRight">
                    <?php echo $form->dropDownList($model, 'status', Posts::getStatusPost()); ?>
                </div>
            </div>

            <div class="formRow">
                <?php echo $form->labelEx($model, 'focus'); ?>
                <div class="formRight">
                    <?php echo $form->dropDownList($model, 'focus', Posts::getIsFocus()); ?>
                </div>
            </div>

            <div class="formRow">
                <?php echo $form->labelEx($model, 'created'); ?>
                <div class="formRight">
                    <?php echo $form->textField($model, 'created'); ?>
                </div>
            </div>

            <div class="formRow">
                <?php echo $form->labelEx($model, 'type'); ?>
                <div class="formRight">
                    <?php // CHtml::dropDownList($name, $select, $data)  ?>
                    <?php echo $form->dropDownList($model, 'type', Posts::getTypePost()); ?>
                </div>
            </div>


            <div class="formRow">
                <?php echo CHtml::submitButton($model->isNewRecord ? 'Lưu' : 'Cập nhật'); ?>
            </div>

            <?php $this->endWidget(); ?>
        </div>
    </div> 
</div> <!-- end class content -->
<script type="text/javascript">
    function convertToSlug(Text)
    {
        // Xử lý ký tự Unicode
        in_chrs = 'áàảãạăắặằẳẵâấầẩẫậđéèẻẽẹêếềểễệóòỏõọôốồổỗộơớờởỡợúùủũụưứừửữựýỳỷỹỵÁÀẢÃẠĂẮẶẰẲẴÂẤẦẨẪẬĐÉÈẺẼẸÊẾỀỂỄỆÍÌỈĨỊíìỉĩịÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢÚÙỦŨỤƯỨỪỬỮỰÝỲỶỸỴ',
                out_chrs = 'aaaaaaaaaaaaaaaaadeeeeeeeeeeeooooooooooooooooouuuuuuuuuuuyyyyyAAAAAAAAAAAAAAAAADEEEEEEEEEEEIIIIIiiiiiOOOOOOOOOOOOOOOOOOUUUUUUUUUUUUYYYYY'
        transl = {};

        eval('var chars_rgx = /[' + in_chrs + ']/g');
        for (var i = 0; i < in_chrs.length; i++)
        {
            transl[in_chrs.charAt(i)] = out_chrs.charAt(i);
        }
        Text = Text.replace(chars_rgx, function(match) {
            return transl[match];
        });

        Text = Text
                .toLowerCase()
                .replace(/ /g, '-')
                .replace(/[^\w-]+/g, '')
                .replace(/--/g, '-');

        // Bỏ đi các ký tự đặc biệt
        return Text;
    }

    $('#Posts_title').keyup(function() {
        title = $('#Posts_title').val();
        $('#Posts_slug').val(convertToSlug(title));
    });
</script>
